package luzhin.frames;

import java.awt.BorderLayout;

import javax.swing.*;

/**
 * Dialog asking user for sides strategies (Manual, AI).
 * @author lacungus
 *
 */
public class InitDialog extends JDialog {
	private static final long serialVersionUID = 372128937L;
	
	static final int MANUAL_STRATEGY_ID = 0;
	static final int AI_STRATEGY_ID = 1;
	
	/**
	 * 
	 * @param mainFrame 
	 * @param initDialogController 
	 */
	public InitDialog(MainFrame mainFrame, InitDialogController initDialogController) {
		super(mainFrame, true);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        
        initFilePanel();
        initStrategyPanel();
        initStartButton();
        
        initDialogController.setInitDialog(this);        
        this.setSize(300, 300);
        this.setVisible(true);
	}

	private JPanel filePanel;
	private JPanel strategyPanel;
	JButton startButton;
	JButton loadButton;
	JTextField gameToLoadField;
	
	JComboBox whiteStrategyBox;
	JComboBox blackStrategyBox;
	
	private void initFilePanel() {
		filePanel = new JPanel();
		filePanel.setLayout(new BoxLayout(filePanel, BoxLayout.PAGE_AXIS));
		
		gameToLoadField = new JTextField(30);
		gameToLoadField.setText("none");
		gameToLoadField.setEditable(false);
		filePanel.add(gameToLoadField);
		
		loadButton = new JButton("Load game");
		filePanel.add(loadButton);

		this.add(filePanel, BorderLayout.NORTH);
	}
	
	private void initStrategyPanel() {
		strategyPanel = new JPanel();
		String[] strategies = {"Manual", "AI"};
		
		strategyPanel.setLayout(new BoxLayout(strategyPanel, BoxLayout.PAGE_AXIS));

		JTextField chooseWhiteStrategyField = new JTextField("Choose white strategy");
		chooseWhiteStrategyField.setEditable(false);
		strategyPanel.add(chooseWhiteStrategyField);		
		whiteStrategyBox = new JComboBox(strategies);
		whiteStrategyBox.setSelectedIndex(0);
		strategyPanel.add(whiteStrategyBox);
		
		JTextField chooseBlackStrategyField = new JTextField("Choose black strategy");
		chooseBlackStrategyField.setEditable(false);
		strategyPanel.add(chooseBlackStrategyField);		
		blackStrategyBox = new JComboBox(strategies);
		blackStrategyBox.setSelectedIndex(1);
		strategyPanel.add(blackStrategyBox);
		
		this.add(strategyPanel, BorderLayout.CENTER);		
	}
	
	private void initStartButton() {
		startButton = new JButton("Start!");
		this.add(startButton, BorderLayout.SOUTH);
	}
	
}
